﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AOC19NET.Controls {
	/// <summary>
	/// Interaction logic for LabeledTextBox.xaml
	/// </summary>
	public partial class LabeledTextBox : UserControl {
		/// <summary>
		/// Useful class that groups a textbox and a label.
		/// </summary>
		public LabeledTextBox() {
			InitializeComponent();
		}

		#region LABEL PROPERTY
		/// <summary>
		/// "Label" property accessor.
		/// </summary>
		public String Label {
			get {
				return (String)GetValue(LabelProperty);
			}
			set {
				SetValue(LabelProperty, (String)value);
			}
		}

		/// <summary>
		/// "Label" property definition and registration.
		/// </summary>
		public static DependencyProperty LabelProperty =
			DependencyProperty.Register(
				"LabelProperty", typeof(String), typeof(LabeledTextBox),
				new PropertyMetadata("Label",
				new PropertyChangedCallback(LabelPropertyChangedCallback)
			)
		);

		/// <summary>
		/// "Label" property change callback.
		/// </summary>
		/// <param name="_Sender">Event sender</param>
		/// <param name="_Arguments">Event arguments.</param>
		public static void LabelPropertyChangedCallback(DependencyObject _Sender, DependencyPropertyChangedEventArgs _Arguments) {
			LabeledTextBox Sender = (LabeledTextBox)_Sender;
			Sender.m_Label.Content = (String)_Arguments.NewValue;
		}
		#endregion

		#region TEXTBOX PROPERTY
		/// <summary>
		/// "TextBox" property accessor.
		/// </summary>
		public String TextBox {
			get {
				return (String)GetValue(TextBoxProperty);
			}
			set {
				SetValue(TextBoxProperty, (String)value);
			}
		}

		/// <summary>
		/// "TextBox" property definition and registration.
		/// </summary>
		public static DependencyProperty TextBoxProperty =
			DependencyProperty.Register(
				"TextBoxProperty", typeof(String), typeof(LabeledTextBox),
				new PropertyMetadata("TextBox",
				new PropertyChangedCallback(TextBoxPropertyChangedCallback)
			)
		);

		/// <summary>
		/// "TextBox" property change callback.
		/// </summary>
		/// <param name="_Sender">Event sender</param>
		/// <param name="_Arguments">Event arguments.</param>
		public static void TextBoxPropertyChangedCallback(DependencyObject _Sender, DependencyPropertyChangedEventArgs _Arguments) {
			LabeledTextBox Sender = (LabeledTextBox)_Sender;
			Sender.m_TextBox.Text = (String)_Arguments.NewValue;
		}
		#endregion

		#region LABEL WIDTH PROPERTY
		/// <summary>
		/// "LabelWidth" property accessor.
		/// </summary>
		public double LabelWidth {
			get {
				return (double)GetValue(LabelWidthProperty);
			}
			set {
				SetValue(LabelWidthProperty, (double)value);
			}
		}

		/// <summary>
		/// "LabelWidth" property definition and registration.
		/// </summary>
		public static DependencyProperty LabelWidthProperty =
			DependencyProperty.Register(
				"LabelWidthProperty", typeof(double), typeof(LabeledTextBox),
				new PropertyMetadata((double)120,
				new PropertyChangedCallback(LabelWidthPropertyChangedCallback)
			)
		);

		/// <summary>
		/// "LabelWidth" property change callback.
		/// </summary>
		/// <param name="_Sender">Event sender</param>
		/// <param name="_Arguments">Event arguments.</param>
		public static void LabelWidthPropertyChangedCallback(DependencyObject _Sender, DependencyPropertyChangedEventArgs _Arguments) {
			LabeledTextBox Sender = (LabeledTextBox)_Sender;
			Sender.m_Label.Width = (double)_Arguments.NewValue;
		}
		#endregion
	}
}
